import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;

import javax.swing.JPanel;

class DrawingZone extends JPanel {
	protected final ArrayList<Snake> snakes;
	protected final Color bgcolor; 
	
	public DrawingZone(ArrayList<Snake> s, Color bg) {
		snakes = s; 
		bgcolor = bg;
	}
	
	protected void drawLine(Graphics g, double x1, double y1, double x2, double y2) {
		int hh = getHeight()/2;
		int hw = getWidth()/2;
		g.drawLine((int)x1+hw, (int)y1+hh, (int)x2+hw, (int)y2+hh);
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		//White background
		g.setColor(bgcolor);
		g.fillRect(0, 0, getWidth(), getHeight());
		//Snake
		for (Snake s: snakes) {
			g.setColor(s.color);
			MyPoint prev = s.pt.getFirst();
			for (MyPoint cur: s.pt) {
				drawLine(g, prev.getX(), prev.getY(), cur.getX(), cur.getY());
				prev = cur;
			}
			drawLine(g, prev.getX(), prev.getY(), s.head.getX(), s.head.getY());
		}
	}
}
